<?php

use yii\db\Migration;

class m160513_060941_alterTable_user extends Migration
{
    const TBL_NAME = '{{%user}}';
    public function up()
    {
        $sql = "
            DROP TABLE IF EXISTS ". self::TBL_NAME .";
            CREATE TABLE ". self::TBL_NAME ." (
              `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
              `username` char(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '手机号',
              `auth_key` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '权限',
              `password_hash` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '密码',
              `password_reset_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '密码重置令牌',
              `access_token` varchar(255)  DEFAULT NULL COMMENT 'api用户认证',
              `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '邮箱',
              `status` smallint(6) DEFAULT '10',
              `level` varchar(255) COLLATE utf8_unicode_ci DEFAULT '1' COMMENT '用户等级',
              `created_at` char(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '注册时间',
              `updated_at` char(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '更新时间',
              `address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '地址',
              `sex` tinyint(2) unsigned DEFAULT NULL COMMENT '性别  保密(0) 男(1) 女(2) ',
              `age` int(3) unsigned DEFAULT NULL COMMENT '年龄',
              `nic_thumb` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '用户头像',
              `nic_name` char(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '昵称',
              `verify_code` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '验证码',
              `verify_time` char(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '验证码生成时间',
              `flag` smallint(1) COLLATE utf8_unicode_ci DEFAULT '1' COMMENT '禁用(0),正常使用(1)',
              PRIMARY KEY (`id`),
              UNIQUE KEY `username` (`username`),
                UNIQUE KEY `access_token` (`access_token`),
              KEY `email` (`email`) USING BTREE
            ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
        ";
        $this->execute($sql);
    }

    public function down()
    {
        echo "m160513_060941_alterTable_user cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
